package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TMarkdown;
import com.ruoyi.system.service.ITMarkdownService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * markdown管理Controller
 * 
 * @author ruoyi
 * @date 2022-01-18
 */
@RestController
@RequestMapping("/system/markdown")
public class TMarkdownController extends BaseController
{
    @Autowired
    private ITMarkdownService tMarkdownService;

    /**
     * 查询markdown管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:markdown:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMarkdown tMarkdown)
    {
        startPage();
        List<TMarkdown> list = tMarkdownService.selectTMarkdownList(tMarkdown);
        return getDataTable(list);
    }

    /**
     * 导出markdown管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:markdown:export')")
    @Log(title = "markdown管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMarkdown tMarkdown)
    {
        List<TMarkdown> list = tMarkdownService.selectTMarkdownList(tMarkdown);
        ExcelUtil<TMarkdown> util = new ExcelUtil<TMarkdown>(TMarkdown.class);
        util.exportExcel(response, list, "markdown管理数据");
    }

    /**
     * 获取markdown管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:markdown:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tMarkdownService.selectTMarkdownById(id));
    }

    /**
     * 新增markdown管理
     */
    @PreAuthorize("@ss.hasPermi('system:markdown:add')")
    @Log(title = "markdown管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMarkdown tMarkdown)
    {
        return toAjax(tMarkdownService.insertTMarkdown(tMarkdown));
    }

    /**
     * 修改markdown管理
     */
    @PreAuthorize("@ss.hasPermi('system:markdown:edit')")
    @Log(title = "markdown管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMarkdown tMarkdown)
    {
        return toAjax(tMarkdownService.updateTMarkdown(tMarkdown));
    }

    /**
     * 删除markdown管理
     */
    @PreAuthorize("@ss.hasPermi('system:markdown:remove')")
    @Log(title = "markdown管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMarkdownService.deleteTMarkdownByIds(ids));
    }
}
